'use strict';
angular.module('nec-admin.user')
    .service('userService', ['$http', '$localStorage', 'serverUrl', 'authService',
        function ($http, $localStorage, serverUrl, authService) {
            var service = this;

            //初始化用户相关信息
            service.initUserInfo = function (userId, username) {
                $localStorage.userInfo = {};
                $localStorage.userInfo.userId = userId;
                $localStorage.userInfo.username = username;
            };

            //获取用户名
            service.getUsername = function () {
                return $localStorage.userInfo.username;
            };

            //获取用户Id
            service.getUserId = function () {
                return $localStorage.userInfo.userId;
            };

            //登出
            service.logout = function () {
                authService.logout();
                $localStorage.userInfo = {};
                $localStorage.hospital = {};
                $localStorage.paperSearchArg = {};
            };

            //用户名是否重复的验证
            service.usernameRepeatCheck = function(username){
                return $http({
                    url: serverUrl + '/uniqueness',
                    method: 'GET',
                    params: {
                        content: username
                    }
                });
            };

        }]);
